<script setup lang="ts">
import {
  setSystemInfo,
  setUrlCode,
  setActivityId,
  setScancode,
  getScancode,
  setAdPopup,
} from '@mixins/info';

interface GlobalData {
  /** 搜索中心点 */
  searchObj: any;
  /** 入口带参类型  qrcode跳扫码 */
  qType: String;
}

const instance = getCurrentInstance();

function getGlobalData() {
  // @ts-ignore
  return instance.proxy.$scope.globalData as GlobalData;
}

const getCode = (option: any) => {
  // #ifdef MP-WEIXIN
  if (option.query.q) {
    let url = decodeURIComponent(option.query.q);
    const couponUrl = import.meta.env.VITE_VUE_APP_COUPON;
    const couponUrl1 = import.meta.env.VITE_VUE_APP_COUPON1;
    if (url.includes(couponUrl)) {
      // 扫码领券
      setActivityId(url.split(couponUrl)[1]);
    } else if (url.includes(couponUrl1)) {
      // 扫码领券
      setActivityId(url.split(couponUrl1)[1]);
    } else {
      // 扫码充电
      if (url.includes('http://w.qclntec.com:8082?')) {
        url = `hlht://${url.split('?')[1]}.MA25JW225/`;
      }
      console.log('codde-------', url);
      setUrlCode(url || '');
    }
  }
  // #endif
};

onLaunch((option: any) => {
  // #ifdef MP-WEIXIN
  if (option.scene === 1011 || option.scene === 1012) {
    getCode(option);
  }
  if (option.scene === 1035) {
    // 公众号菜单
    const type = option.query.type;
    if (type === 'qrcode') {
      const globalData = getGlobalData();
      globalData.qType = type;
    }
  }
  // #endif
  console.log('App Launch---', option);
  setSystemInfo();
  uni.offWindowResize(setSystemInfo);
  uni.onWindowResize(setSystemInfo);
});
onShow((option: any) => {
  // #ifdef MP-WEIXIN
  console.log('小程序版本号-----', uni.getAccountInfoSync().miniProgram.version);
  if ((option.scene === 1011 || option.scene === 1012) && getScancode() !== '1') {
    console.log('App Show---1111-', getScancode());
    getCode(option);
  }
  if (option.scene === 1035 && getScancode() !== '1') {
    // 公众号菜单
    const type = option.query.type;
    if (type === 'qrcode') {
      const globalData = getGlobalData();
      globalData.qType = type;
    }
  } else {
    const globalData = getGlobalData();
    globalData.qType = '';
  }
  // if (
  //   getScancode() === '0' &&
  //   (option.scene === 1007 || option.scene === 1089 || option.scene === 1011)
  // ) {
  if (getScancode() === '0') {
    setAdPopup(true);
  }
  console.log('App Show---', option, getScancode());
  setScancode('0');
  // #endif
  uni.hideTabBar();
});
onHide(() => {
  console.log('App Hide-----', getScancode());
});
</script>
<style>
@import '@/static/icon/iconfont.css';
/* #ifdef H5 */
@import 'vant/lib/index.css';
.van-nav-bar__arrow {
  font-size: 24px;
}
.van-nav-bar .van-icon {
  color: #000000;
}
.van-nav-bar {
  /* background-color: transparent; */
  background-color: #ffffff;
}
.van-nav-bar__content {
  height: 44px;
}
.van-hairline--bottom:after {
  border: none;
}
.van-nav-bar__right:active {
  opacity: 1;
}
/* .native-footer-bar {
  position: fixed;
  width: 100vw;
  bottom: 0;
}
.native-status-bar {
  position: fixed;
  width: 100vw;
  top: 0;
} */
/* #endif */
</style>
